/*
 * =====================================================================================
 *
 *       Filename:  utils_net.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2018年07月21日 16时23分51秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef _UTILS_NET_H
#define _UTILS_NET_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/if_arp.h>

int tcpsock_create(const char *ip, unsigned short port, int backlog);
int tcpsock_connect(const char *ip, unsigned short port);
int tcpsock_connect_timeout(const char *ip, unsigned short port, int timeout);
int sock_set_nonblock(int fd);
int sock_set_reuseaddr(int _fd);
int sock_get_peeraddr(int fd, char *ip, unsigned short *port);
int sock_get_localaddr(int fd, char *ip, unsigned short *port);

int udpsock_create(const char *_ip, unsigned short _port);
int udpsock_create_rand_port(const char *_ip, unsigned short *_port);
int udpsock_create_rand_port_couple(const char *ip, unsigned short *_port_rtp, int *fd_rtp, int *fd_rtcp, int try);
int udpsock_connect(int fd, const char *ip, unsigned short port);


/* interfaces */
#define LEN_IP_STR  (sizeof("255.255.255.255"))
#define LEN_MAC_STR (sizeof("FF:FF:FF:FF:FF:FF"))


int get_all_interfaces();
int get_eth_ip(const char *eth_name, char *ip, int len);
int get_eth_mask(const char *eth_name, char *mask, int len);
int get_eth_broadcast(const char *eth_name, char *broadcast, int len);
int get_eth_mac(const char *eth_name, char *mac, int len);
int get_eth_dstip(const char *eth_name, char *dstip, int len);
int get_eth_metric(const char *eth_name);
int get_eth_mtu(const char *eth_name);
short get_eth_flags(const char *eth_name);

enum eth_action {
    ETH_GET_IP = 0,
    ETH_GET_MASK,
    ETH_GET_DSTIP,
    ETH_GET_BROADCAST,
    ETH_GET_MAC,
    ETH_GET_METIC,
    ETH_GET_MTU,
    ETH_GET_FLAGS,
    
    ETH_SET_IP,
    ETH_SET_MASK,
    ETH_SET_DSTIP,
    ETH_SET_BROADCAST,
    ETH_SET_MAC,
    ETH_SET_METIC,
    ETH_SET_MTU,
    ETH_SET_FLAGS,

    ETH_ACTION_MAX,
};


#endif

